<%@ include file="/common/taglibs.jsp"%>
<c:set var="toPayUrl"><spring:url value="/order/orderDetailsInfo.html"/></c:set>
<head>
	<title><spring:message code="shoppingCart.header"/></title>
	<script type="text/javascript">
	$(document).ready(function(){
		$(".aButton").button();
		
		$("#previous").click(function(){
			history.back();
		});
		$("#toPay").click(function(){
			location.assign("${toPayUrl}");
		});
	});
	</script>
</head>
<div class="ui-widget summary-booklist">
	<h1 class="ui-helper-reset ui-widget-header ui-corner-top booklist-header">
		<spring:message code="shoppingCart.header"/>
	</h1>
	<div class="ui-widget-content ui-corner-bottom">
		<form action="<spring:url value="/shoppingCart/updateQuantities.html"/>" method="post">
		<table width="100%" class="shoppingCart">
			<tr>
				<th><spring:message code="shoppingCart.item.book.name"/></th>
				<th><spring:message code="shoppingCart.item.book.unitPrice"/></th>
				<th><spring:message code="shoppingCart.item.quantity"/></th>
				<th><spring:message code="shoppingCart.item.total"/></th>
				<th><spring:message code="shoppingCart.item.book.inventory.status"/></th>
				<th><spring:message code="shoppingCart.item.book.inventory.quantity"/></th>
				<th><spring:message code="shoppingCart.remove" /></th>
				<th style="width: 0px;"></th>
			</tr>
			<c:forEach var="item" items="${shoppingCart.shoppingCartItems}">
				<tr style="border-bottom: 1px solid #DDDDDD;">
					<td><a href="<spring:url value='/book/details.html'>
						<spring:param name='bookId' value='${item.book.id}' />
						</spring:url>"><c:out value="${item.book.name}"/></a></td>
					<td><c:out value="${item.book.unitPrice}"/></td>
					<td><input type="text" name="quantities" style="width:40px;" value="<c:out value="${item.quantity}"/>" /></td>
					<td><c:out value="${item.totalPrice}"/></td>
					<td><spring:message code="${sf:getInventoryStatusMessageCode(item.book.inventory.status)}"/></td>
					<td><c:out value="${item.book.inventory.availableQuantity}"/></td>
					<td><a href="<spring:url value='/shoppingCart/removeBook.html'>
						<spring:param name="bookId" value="${item.book.id}"/>
						</spring:url>"><spring:message code="shoppingCart.remove" /></a></td>
					<td><input style="width:0px;" type="hidden" name="bookIds" value="${item.book.id}"/></td>
				</tr>
			</c:forEach>
		</table>
		<p></p>
		<table width="100%">
			<tr>
				<td align="center"><button class="aButton" type="submit"><spring:message code="shoppingCart.updateQuantity"/></button></td>
			</tr>
			<tr>
				<td style="text-align: center;"><spring:message code="shoppingCart.description" arguments="${shoppingCart.totalQuantity},${shoppingCart.totalPrice}"/></td>
			</tr>
		</table>
		</form>
		<p></p>
		<table width="100%">
			<tr>
				<td><button id="previous" class="aButton" style="float: left; margin-left: 10px;"><spring:message code="shoppingCart.continue"/></button></td>
				<td>
				<c:choose>
					<c:when test="${fn:length(shoppingCart.shoppingCartItems) == 0}">
						<button id="toPay" class="aButton" disabled="disabled" style="float: right; margin-right: 10px;"><spring:message code="shoppingCart.pay"/></button>
					</c:when>
					<c:otherwise>
						<button id="toPay" class="aButton" style="float: right; margin-right: 10px;"><spring:message code="shoppingCart.pay"/></button>
					</c:otherwise>
				</c:choose>
				</td>
			</tr>
		</table>
		
	</div>
</div>